from flask import Flask, Response, request, Blueprint
from flask_jwt_extended import JWTManager, create_access_token, jwt_required, get_jwt_identity

from app.service.SettlementPreferenceService import SettlementPreferenceService
from app.common.commonMessage import CommonMassages
from app.config.db import DBUtils

import json
app = Flask(__name__)
# 创建蓝图
settlement_preference_bp = Blueprint('settlement_preference', __name__ , url_prefix='/kshx')

settlementPreferenceService = SettlementPreferenceService()

# 获取session
db_utils = DBUtils()
session = db_utils.get_session()

@settlement_preference_bp.route('/settlementPreference', methods=['GET'])
# @jwt_required()
def get_settlement_preference():
    companyName = request.args.get("companyName", type=str)
    company_type = request.args.get("company_type", type=int)
    start_date = request.args.get("start_date", type=str)
    end_date = request.args.get("end_date", type=str)
    data1 = settlementPreferenceService.select_trading_indicators_data(session, companyName, company_type, start_date, end_date)
    data2 = settlementPreferenceService.select_settlement_statistics_data(session, companyName, company_type, start_date, end_date)
    data = {
        'jyzb': data1, # 交易指标
        'jstj': data2  # 结算统计
    }
    if data is not None:
        respResult = {
            "code": 200,
            "data": data,
            "message": CommonMassages.CCD_SELECT_SUCCESS.value
        }
    else:
        respResult = {
            "code": 400,
            "data": None,
            "message": CommonMassages.CCD_SELECT_FAILED.value
        }
    resp_data = json.dumps(respResult, ensure_ascii=False)
    return Response(resp_data, content_type='application/json')